//
//  BindingDeviceView.swift
//  DaRings
//
//  Created by 易先生 on 2022/10/28.
//

import UIKit
import MYModule

class MyHomeDeviceContainerView: View {

    override func makeUI() {
        super.makeUI()
        
        batteryContainer.addSubview(batteryImg)
        batteryContainer.addSubview(batteryChargImg)
        
        batteryView.addArrangedSubview(batteryLabel)
        batteryView.addArrangedSubview(batteryContainer)
        
        
        self.addSubview(devicePreviewImageView)
        self.addSubview(deviceName)
        self.addSubview(stateLabel)
        self.addSubview(macAddressLabel)
        self.addSubview(batteryView)
        self.addSubview(removeButton)
        
        batteryImg.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-1.5)
            make.top.left.equalToSuperview().offset(1.5)
            make.right.lessThanOrEqualToSuperview().offset(-2.5)
            make.width.equalToSuperview().multipliedBy(1).priority(999)
        }
        
        batteryChargImg.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-1.5)
            make.top.left.equalToSuperview().offset(1.5)
            make.right.equalToSuperview().offset(-2.5)
        }
        
        batteryContainer.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 24, height: 11))
        }
        
        devicePreviewImageView.snp.makeConstraints { make in
            make.trailing.equalToSuperview()
            make.size.equalTo(CGSize(width: 170, height: 164))
            make.centerY.equalToSuperview()
        }
        
        deviceName.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.leading.equalToSuperview()
            make.trailing.equalTo(devicePreviewImageView.snp.leading).offset(-20)
        }
        
        macAddressLabel.snp.makeConstraints { make in
            make.top.equalTo(deviceName.snp.bottom).offset(5)
            make.leading.equalToSuperview()
        }
        
        stateLabel.snp.makeConstraints { make in
            make.top.equalTo(macAddressLabel.snp.bottom).offset(5)
            make.leading.equalToSuperview()
        }
        
        batteryView.snp.makeConstraints { make in
            make.top.equalTo(stateLabel.snp.bottom).offset(6)
            make.leading.equalToSuperview()
        }
        
        removeButton.snp.makeConstraints { make in
            make.top.equalTo(batteryView.snp.bottom).offset(10)
            make.leading.equalToSuperview()
            make.bottom.equalToSuperview()
        }

    }
    
    public lazy var devicePreviewImageView:ImageView = {
        let devicePreviewImageView = ImageView()
        devicePreviewImageView.image = UIImage(named: "ic_ring")
        return devicePreviewImageView
    }()
    
    public lazy var deviceName:Label = {
        let deviceName = Label()
        deviceName.font = Fonts.boldSystemFont(ofSize: 40)
        deviceName.numberOfLines = 0
        deviceName.textColor = UIColor.assist_222222
        return deviceName
    }()
    
    public lazy var macAddressLabel:Label = {
        let macAddressLabel = Label()
        macAddressLabel.font = Fonts.systemFont(ofSize: 12)
        macAddressLabel.textColor = UIColor.assist_222222
        macAddressLabel.numberOfLines = 0
        return macAddressLabel
    }()
    
    public lazy var stateLabel:Label = {
        let stateLabel = Label()
        stateLabel.font = Fonts.systemFont(ofSize: 12)
        stateLabel.numberOfLines = 0
        stateLabel.text = "ble_disconnected".language
        stateLabel.textColor = UIColor.assist_222222
        return stateLabel
    }()

    
    public lazy var batteryLabel:Label = {
        let batteryLabel = Label()
        batteryLabel.font = Fonts.systemFont(ofSize: 12)
        batteryLabel.textColor = UIColor.assist_222222
        batteryLabel.text = "--%"
        return batteryLabel
    }()
    
    public lazy var batteryView:StackView = {
        let batteryView = StackView()
        batteryView.axis = .horizontal
        batteryView.spacing = 3
        batteryView.alignment = .center
        
        return batteryView
    }()
    
    public lazy var batteryImg:ImageView = {
        let batteryImg = ImageView.init(frame: CGRect(x: 1, y: 1, width: 22, height: 9))
        batteryImg.image = UIImage(named: "ic_battery_1")
        return batteryImg
    }()
    
    public lazy var batteryChargImg:ImageView = {
        let batteryChargImg = ImageView.init(frame: CGRect(x: 1, y: 1, width: 22, height: 9))
        
        batteryChargImg.image = UIImage(named: "ic_battery_charging")
        return batteryChargImg
    }()
    
    public lazy var batteryContainer:ImageView = {
        let batteryContainer = ImageView.init(frame: .zero)
        batteryContainer.image = UIImage(named: "ic_battery_0")
        return batteryContainer
    }()
    
    
    public lazy var removeButton:Button = {
        let removeButton = Button(type: .custom)
        removeButton.backgroundColor = UIColor.assist_EEEEEE
        removeButton.cornerRadius = 8
        removeButton.setTitle("tip_remove_device".language, for: .normal)
        removeButton.setTitleColor(UIColor.assist_A9A9A9, for: .normal)
        removeButton.titleLabel?.font = Fonts.today_tip_3()
        removeButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 21, bottom: 5, right: 21)
        return removeButton
    }()

}
